package com.his.server.jdbc;

import java.lang.reflect.Method;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.sql.Connection;
import java.sql.PreparedStatement;
import org.apache.commons.lang.StringUtils;

import com.his.server.consts.ServerConsts;

public class SQLHandler implements InvocationHandler {

	PreparedStatement pst;

	public PreparedStatement Bind(PreparedStatement st) {

		this.pst = st;

		PreparedStatement proxypst = (PreparedStatement) Proxy
				.newProxyInstance(st.getClass().getClassLoader(),
						new Class[] { PreparedStatement.class }, this);

		return proxypst;
	}

	public Object invoke(Object proxy, Method method, Object aobj[])
			throws Throwable {

		Object obj = null;

		if (!StringUtils.equals(method.getName(),
				ServerConsts.METHOD_CLOSE)) {

			obj = method.invoke(pst, aobj);
		}

		return obj;
	}

}